package org.meb.lotrlcg.web.ctrl;

import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

import org.apache.commons.lang.StringUtils;
import org.meb.lotrlcg.db.model.Card;
import org.meb.lotrlcg.db.model.CardType;

@Getter
@Setter
public class CardItem {

	@NonNull
	private Card card;
	private String styleClass;
	private String traits[] = new String[3];

	public CardItem(Card card) {
		this.card = card;
		CardType typeCode = card.getTypeCode();
		if (typeCode.isEncounterDeck()) {
			this.styleClass = "encounter-deck";
		} else if (typeCode.isQuestDeck()) {
			this.styleClass = "quest-deck";
		} else if (typeCode.isPlayerDeck()) {
			this.styleClass = "player-deck " + card.getSphereCode().toString().toLowerCase();
		}
		
		if (StringUtils.isNotBlank(card.getTrait())) {
			traits = card.getTrait().split("\\.", -1);
			for (int i = 0; i < traits.length; i++) {
				traits[i] = StringUtils.trimToNull(traits[i]);
				if (traits[i] != null) {
					traits[i] += ".";
				}
			}
		}
	}
}
